<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>闭包之累加器</title>
</head>
<body>

</body>
<script>
    let count = 0;// 原始数据
    /**
     * 累加函数
     */
    function totalizr() {
        count++;
        console.log(count,'demo1');
    }
    let timer = setInterval(()=>{
        if(count === 9){ // 进入为 9
            console.log(9,'there is 9-2'); // 后执行
        }
        totalizr(); // 执行完结果为9  为9进入，执行结束后为10
        if(count === 9){ //  执行
            console.log(9,'there is 9-1'); // 先执行
        }
        if(count>10){
            clearInterval(timer)
        }
    },500)
</script>
<script>
    /**
     * 失败的作品
     */

    /**
    function totalizr2(count = 0) {
        count++;
        function add() {
            console.log(count,'demo2');
            return count
        }
        return add();
    }
   let timer2 = setInterval(()=>{
       let c = totalizr2();
       if(c>10){
           clearInterval(timer2)
       }
       totalizr2(c)
   },500)
    **/
</script>
<script>
    function totalizr3() {
        var count = 0;
        function log() {
            count++
            console.log(count,'demo3');
            return count
        }
        return log
    }
    let fun = null;
    fun = totalizr3();

    let timer3 = setInterval(()=>{

        if(fun()>10){
            clearInterval(timer3)
        }
    },500)


</script>

</html>
